package com.ruoyi.live.base.security;

import com.ruoyi.common.utils.sign.Md5Utils;
import org.springframework.security.crypto.password.PasswordEncoder;

public class JudgerPasswordEncoder implements PasswordEncoder {
    @Override
    public String encode(CharSequence rawPassword) {
        if (rawPassword == null) {
            throw new IllegalArgumentException("rawPassword cannot be null");
        } else {
            Long md5 = Md5Utils.getMD5((String) rawPassword);
            return md5.toString();
        }
    }

    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
        if (rawPassword == null) {
            throw new IllegalArgumentException("rawPassword cannot be null");
        } else if (encodedPassword != null && encodedPassword.length() != 0) {
            Long md5 = Md5Utils.getMD5((String) rawPassword);
            return md5.toString().equals(encodedPassword);
        } else {
            return false;
        }
    }
}
